//
//  CaseManageCell.m
//  QuickCure37
//
//  Created by 马文星 on 16/6/20.
//  Copyright © 2016年 Demos. All rights reserved.
//

#import "CaseManageCell.h"
#import "CaseDTO.h"

@interface CaseManageCell ()

//圆球
@property (nonatomic, strong) UIImageView *img_box;
//线
@property (nonatomic, strong) UIView *lineV;

@property (nonatomic, strong) UILabel *timeLab;

@property (nonatomic, strong) UIImageView *imageV; //上传的图片

//疾病类型
@property (nonatomic, strong) UILabel *t_caseTypeLab;

@property (nonatomic, strong) UILabel *caseTypeLab;

//疾病细分
@property (nonatomic, strong) UILabel *t_baseCaseClassLab;

@property (nonatomic, strong) UILabel *baseCaseClassLab;

@property (nonatomic, strong) UILabel *caseDescLab;



@end

@implementation CaseManageCell



-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{

    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];

    if (self) {

        [self setupUI];
        [self addLayoutSubviews];
   }
    return self;
}

/** 重写DTO */
- (void)setDto:(CaseDTO *)dto{
    _dto = dto;
    
    self.timeLab.text = dto.timeString;
    
    if (dto.imageData == nil) {
        
        self.imageV.image = [UIImage imageNamed:@"good_image_default"];
        
        
        [self.imageV mas_updateConstraints:^(MASConstraintMaker *make) {
            
            make.top.mas_equalTo(self.timeLab.mas_bottom).offset(5);
            make.left.mas_equalTo(self.timeLab.mas_left);
            make.size.mas_equalTo(CGSizeMake(0.1, 0.1));
        }];
        
    }else{
    
        [self.imageV mas_updateConstraints:^(MASConstraintMaker *make) {
            
            make.size.mas_equalTo(CGSizeMake(80, 80));
            make.top.mas_equalTo(self.timeLab.mas_bottom).offset(5);
            make.left.mas_equalTo(self.timeLab.mas_left);
        }];
        self.imageV.image = [UIImage imageWithData:dto.imageData];
    }
    
    self.caseTypeLab.text = dto.caseType;
    self.baseCaseClassLab.text = dto.caseTypeDetail;
    
    self.caseDescLab.text = (dto.caseDesc.length==0)? @"暂没有病症描述":dto.caseDesc;
}

- (void)setupUI{

    //1.
    self.img_box = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"illness_rb_img_sel.png"]];
    [self addSubview:self.img_box];
    
    //2.
    self.lineV = [[UIView alloc] init];
    self.lineV.backgroundColor = kThemeColor;
    [self addSubview:self.lineV];
    
    //3.
    self.timeLab = [[UILabel alloc] init];
    self.timeLab.textColor = LIGHT_GRAY_COLOR;
    self.timeLab.font = FONT(16);
    [self addSubview:self.timeLab];
    self.timeLab.text = @"16-06-20 16:35:18";
    
    //4.
    self.imageV = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"good_image_default"]];
    [self addSubview:self.imageV];

    //4.
    self.t_caseTypeLab = [[UILabel alloc] init];
    self.t_caseTypeLab.font = FONT(16);
    self.t_caseTypeLab.text = @"疾病类型：";
    [self addSubview:self.t_caseTypeLab];
    
    //5.
    self.caseTypeLab = [[UILabel alloc] init];
    self.caseTypeLab.font = FONT(16);
    self.caseTypeLab.textColor  =LIGHT_GRAY_COLOR;
    [self addSubview:self.caseTypeLab];
    self.caseTypeLab.text = @"心血管";
    
    //6.
    self.t_baseCaseClassLab = [[UILabel alloc] init];
    self.t_baseCaseClassLab.font = FONT(16);
    self.t_baseCaseClassLab.text = @"基本类型：";
    [self addSubview:self.t_baseCaseClassLab];
    
    //6.
    self.baseCaseClassLab = [[UILabel alloc] init];
    self.baseCaseClassLab.font = FONT(16);
    self.baseCaseClassLab.text = @"心血管疾病";
    self.baseCaseClassLab.textColor = LIGHT_GRAY_COLOR;
    [self addSubview:self.baseCaseClassLab];
    
    //7.
    self.caseDescLab = [[UILabel alloc] init];
    self.caseDescLab.textColor = LIGHT_GRAY_COLOR;
    self.caseDescLab.font = FONT(14);
    [self addSubview:self.caseDescLab];
    self.caseDescLab.text = @"基本类型基基本类型基本类型基本类型基本类型基本类型基本类型基本类型基本类型基本类型基本类型基本类型基本类型本类型基本类型基本类型基本类型基本类型基本类型基本类型";
    self.caseDescLab.numberOfLines = 0;
    self.caseDescLab.lineBreakMode = NSLineBreakByTruncatingTail;
    
}

-(void)addLayoutSubviews{
//    [super layoutSubviews];


    [self.img_box mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(0);
        make.size.mas_equalTo(CGSizeMake(15, 15));
        make.centerX.mas_equalTo(self.mas_leading).offset(25);
    }];
    
    [self.lineV mas_makeConstraints:^(MASConstraintMaker *make) {

        make.top.mas_equalTo(self.img_box.mas_bottom);
        make.width.mas_equalTo(1);
        make.centerX.equalTo(self.img_box);
        make.bottom.mas_equalTo(0);
        
    }];
    
    [self.timeLab mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.left.mas_equalTo(self.img_box.mas_right).offset(10);
        make.height.mas_equalTo(20);
        make.top.mas_equalTo(0);
    }];
    
    
    [self.imageV mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.size.mas_equalTo(CGSizeMake(80, 80));
        make.top.mas_equalTo(self.timeLab.mas_bottom).offset(5);
        make.left.mas_equalTo(self.timeLab.mas_left);
    }];
    
    
    [self.t_caseTypeLab mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(self.imageV.mas_right).offset(10);
        make.top.mas_equalTo(self.imageV.mas_top);
        make.height.mas_equalTo(25);
    }];
    
    [self.caseTypeLab mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.left.mas_equalTo(self.t_caseTypeLab.mas_right).offset(0);
        make.top.mas_equalTo(self.t_caseTypeLab.mas_top);
        make.height.mas_equalTo(25);
        
    }];
    
    
    [self.t_baseCaseClassLab mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(self.imageV.mas_right).offset(10);
        make.top.mas_equalTo(self.t_caseTypeLab.mas_bottom);
        make.height.mas_equalTo(25);
    }];
    
    [self.baseCaseClassLab mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(self.t_baseCaseClassLab.mas_right).offset(0);
        make.top.mas_equalTo(self.t_baseCaseClassLab.mas_top);
        make.height.mas_equalTo(25);
    }];
    
    
    
    [self.caseDescLab mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(self.t_baseCaseClassLab.mas_left);
        make.top.mas_equalTo(self.t_baseCaseClassLab.mas_bottom);
        make.right.mas_equalTo(-10);
        make.bottom.mas_equalTo(-10);
    }];
    
}



@end
